package com;

import com.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration //说明当前类是一个配置类 作用类似applicationContext.xml
@ComponentScan //扫描当前包及其子包下的所有类，并将其注册为Bean
public class AppConfig {
    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        User user = context.getBean(User.class);
        //上两行作用等同于下面两行
        System.out.println(user);
        UserService userService = (UserService) context.getBean("userService");
        boolean flag = userService.login("admin", "123456");
        if (flag) {
            System.out.println("登录成功");
        }else {
            System.out.println("登录失败");
        }
    }
}
